<?php
    $url = new Url(); 
    $forder_upload = "appvideo";  
    $link_avatar = Yii::app()->params["urlImages"] . "upload_avatar_video.php?forder_upload=" . $forder_upload;    
    $arr_status = LoadConfig::$status;
?>
<link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript">
    window.onload = function() {
        var configUploadData = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:0,
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_avatar;?>", 
            file_types: "*.jpg;*.jpeg;*.png;*.gif", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }

        
        configUpload(configUploadData); 
           
    };

    function uploadResponse(serverData){  
        try {
            $("#txtFileName").val(""); 
            var response = $.parseJSON(serverData); // eval( "(" + serverData + ")" );      
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;
            $("#picture").val(filename);
            $("#show_pic").html('<img src="<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'" class="img-100" alt="pic">')
        } catch (e) {

        };
    }

    function ajaxSaveVideo(){
        var title_video = $("#title_video").val();
        var link = $("#link").val();
        var view = $("#view").val();
        var picture = $("#picture").val();
        var status = $("#status").val();
        var type = $("#type").val();
        var strUrl = "<?php echo $url->createUrl("downloadAppVideo/ajaxSaveVideo") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                title_video:title_video,
                link:link,
                view:view,
                link:link,
                type:type,
                picture:picture,
                status:status,
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm thành công');
                    window.location = '<?php echo $url->createUrl("downloadAppVideo/index")?>';
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
</script>

<div class="main clearfix">
    <div class="box clearfix bottom30">    
        <div class="col-570">  
            <ul class="form1">
                <li class="clearfix"><label><strong>Tên video </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:360px" value="" id="title_video"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Link down </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:360px" value="" id="link"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Danh mục </strong>:</label>
                    <div class="filltext">
                        <select id="type" style="width: 200px;">
                            <option value="0" >- Video Hot -</option>
                            <option value="1" >- Video New -</option>
                            <option value="2" >- Download nhiều -</option>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label><strong>View </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:180px" value="" id="view"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Ảnh minh họa </strong>:</label>
                    <div class="filltext">
                        <p>
                            <input type="hidden" id="txtFileName" readonly="readonly"/>
                            <input type="text" id="urlFile" style="border:1px solid #DFDFDF; width: 200px;">                            
                            <span id="spanButtonPlaceHolder"></span>
                        </p>
                        <p><i>Định dạng file: *.jpg;*.jpeg;*.png;*.gif(Dung lượng ko được quá 2 MB)</i></p>
                        <br/>
                        <div class="fieldset flash" id="fsUploadProgress">
                            <span class="legend">File upload</span>
                        </div>

                        <input type="hidden" id="picture" value=""/>
                        <p id="show_pic"></p>
                    </div>
                </li>
                <!--<li class="clearfix"><label><strong>Tóm tắt</strong>:</label>
                    <div class="filltext">
                        <textarea cols="5" rows="5" style="width:420px; height:120px" id="introtext"></textarea>
                    </div>
                </li>-->
                
                <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                    <div class="filltext">
                        <select style="width:203px;" id="status">
                            <?php foreach($arr_status as $key=>$value){?>
                                <option value="<?php echo $key;?>"><?php echo $value?></option>
                                <?php }?>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input id="button_save" onclick="ajaxSaveVideo();" type="button" value=" Thêm mới " class="btn-bigblue"> 
                        &nbsp;
                        <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext" style="color: red;" id="show_error"></div>
                </li>
            </ul>
        </div>
        <div class="col5">&nbsp;</div>
        <div class="col-570">
            <div class="box">
                <ul class="form">
                    <li class="clearfix"><label>&nbsp;</label>
                        <div class="filltext">
                            <p id="mediaplayer"> </p>  
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp']; ?>/js/mediaplayer/jwplayer.js"></script>